/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ThreadClient;

import ObjectFileOptionsClient.ObjectFile;
import ObjectFileOptionsClient.ObjectFileOption;
import Packets.pkValue;
import StaticClass.ArrSocket;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Oho
 */
public class ThreadMain extends Thread {

    ObjectInputStream in;
    ObjectOutputStream out;
    private String Command;
    private Socket sk;

    public ThreadMain(Socket sk) {
        this.sk = sk;


    }

    public ThreadMain(ObjectInputStream in, String command) {
        this.in = in;
        this.Command = command;
    }

    public ThreadMain() {
    }
    ObjectFileOption op;

    public void ThreadRead() throws IOException {
        if (in == null) {
            in = new ObjectInputStream(sk.getInputStream());
        }
        op = new ObjectFile(sk, in, out);
        op.progessRead();
        //in=null;

        //  ArrSocket.tm .start();
        // in.close();

    }

    public void ThreadWrite(pkValue pk) throws IOException {
        if (out == null) {
            out = new ObjectOutputStream(sk.getOutputStream());
        }
        op = new ObjectFile(sk, in, out);
        op.progessWrite(pk);



    }

    @Override
    public void run() {
        while (true) {
            try {
                ThreadRead();
            } catch (IOException ex) {
                // this.suspend();
                //this.suspend();
                System.out.print(ex);
//                JOptionPane.showMessageDialog(null, ex);
                // new ThreadMain(sk).start();
            }
        }
        //ThreadWrite();
        //if(vl.getCommand() ==0)

        //lenh chat
        //1 : lenh gui tin nhan 
        //2: lenh ....


    }

    /**
     * @return the Command
     */
    public String getCommand() {
        return Command;
    }

    /**
     * @param Command the Command to set
     */
    public void setCommand(String Command) {
        this.Command = Command;
    }

    /**
     * @return the sk
     */
    public Socket getSk() {
        return sk;
    }

    /**
     * @param sk the sk to set
     */
    public void setSk(Socket sk) {
        this.sk = sk;
    }
}
